﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using StyleMVVM.Data;

namespace StyleMVVM.Messenger
{
	public delegate void JSCallback(object message);

	/// <summary>
	/// IDispatchedMessenger allows you to send messages between loosely coupled consumers.
	/// Note: The default implementation of DispatchedMessenger uses WeakActions to call back consumers
	/// so there is no need to unregister for garbage collection reasons.
	/// </summary>
	public interface IDispatchedMessenger
	{
		/// <summary>
		/// Sends a message of Type T to consumers.
		/// </summary>
		/// <param name="message">message to send, cannot be null</param>
		void Send(object message);

		/// <summary>
		/// Registers an action as a consumer of type T messages.
		/// </summary>
		/// <typeparam name="T">message Type</typeparam>
		/// <param name="callback">message handler</param>
		void Register(object callback);

		/// <summary>
		/// Registers an action as a consumer of type T messages.
		/// </summary>
		/// <typeparam name="T">message Type</typeparam>
		/// <param name="callback">message handler</param>
		/// <param name="background">should it be called back on a background thread</param>
		/// <param name="holdReference"> </param>
		void Register(object callback, bool background, bool holdReference);

		/// <summary>
		/// Registers a method info on a target for callback later.
		/// </summary>
		/// <typeparam name="T">message Type</typeparam>
		/// <param name="target">handler object</param>
		/// <param name="methodName"> </param>
		/// <param name="background"> </param>
		/// <param name="holdReference"> </param>
		void RegisterMethod(object target, string methodName, bool background, bool holdReference);

		/// <summary>
		/// Registers a JavaScript callback
		/// </summary>
		void RegisterJSCallback(TypeWrapper messageType, JSCallback callback, bool background);

		/// <summary>
		/// Unregisters a consumer handler
		/// </summary>
		/// <param name="callback">action to unregister</param>
		void Unregister(object callback);

		/// <summary>
		/// Allows you to register all methods on an object marked with MessageHandler attributes 
		/// </summary>
		/// <param name="handlerObject"></param>
		void RegisterObjectHandlers(object handlerObject);

		/// <summary>
		/// Allows you to unregister all methods on an object marked with MessageHandler attributes 
		/// </summary>
		/// <param name="handlerObject"></param>
		void UnregisterObjectHandlers(object handlerObject);
	}
}